<template>
  <view class="container">
    <view class="jione">
      <text class="fenname">分佣金额合计</text>
      <text class="fennum">¥ <text class="nums">{{tot}}</text> </text>
    </view>
    <mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ use: false }" :up="upOption"
      @up="upCallback">
      <view class="help cont-box b-f" v-for="(item, index) in list.content" :key="index" @click="onTargetDetail(item.id)">
        <view class="title-one">
          <text class="title">{{ item.typeName }}</text>
          <text class="shuzi" :class="item.orderInfo.payAmount>=0?'lv':''">{{ item.orderInfo.payAmount }}</text>
        </view>
        <view class="content">
          <text>{{ formatTimeToYMDHM(item.updateTime) }}</text>
        </view>
      </view>
    </mescroll-body>
  </view>
</template>

<script>
  import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
  import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
  import * as HelpApi from '@/api/help'
  import { getEmptyPaginateObj, getMoreListData } from '@/utils/app'

  const pageSize = 15;

  export default {
    components: {
      MescrollBody
    },
    mixins: [MescrollMixin],
    data() {
      return {
        list: getEmptyPaginateObj(),
        // 上拉加载配置
        upOption: {
          // 首次自动执行
          auto: true,
          // 每页数据的数量; 默认10
          page: { size: pageSize },
          // 数量要大于3条才显示无更多数据
          noMoreSize: 3,
          // 空布局
          empty: {
            tip: '亲，暂无相关数据'
          }
        },
        tot:0
      }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {},

    methods: {

      /**
       * 上拉加载的回调 (页面初始化时也会执行一次)
       * 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
       * @param {Object} page
       */
      upCallback(page) {
        const app = this
        // 设置列表数据
        app.getHelpList(page.num)
          .then(list => {
            const curPageLen = list.content.length;
            const totalSize = list.content.totalElements;
            app.mescroll.endBySize(curPageLen, totalSize);
          })
          .catch(() => app.mescroll.endErr())
      },

      // 获取帮助列表
      getHelpList(pageNo = 1) {
        const app = this
        return new Promise((resolve, reject) => {
          HelpApi.fenlist({ page: pageNo })
            .then(result => {
              // 合并新数据
              console.log(result)
              const newList = result.data.dataList;
              app.list.content = getMoreListData(newList, app.list, pageNo);
              console.log(app.list.content)
              app.tot = result.data.tot
              resolve(newList);
            }).catch(() => app.mescroll.endErr());
        })
      },
      
      // 跳转文章详情页
      onTargetDetail(articleId) {
        this.$navTo('pages/article/detail', { articleId });
      },
      /**
     * 时间戳转指定格式（年.月.日 时:分）
     * @param {number} timestamp - 13位时间戳（如 1758321686000）
     * @returns {string} 格式化后的时间（如 2025.07.20 14:28）
     */
    formatTimeToYMDHM(timestamp) {
      const date = new Date(timestamp);
      // 提取年、月、日（月/日补0至2位）
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需+1
      const day = String(date.getDate()).padStart(2, '0');
      // 提取时、分（补0至2位）
      const hours = String(date.getHours()).padStart(2, '0');
      const minutes = String(date.getMinutes()).padStart(2, '0');
      // 拼接格式
      return `${year}.${month}.${day} ${hours}:${minutes}`;
    }
    }
  }
</script>

<style lang="scss" scoped>
  .help {
    border-bottom: 2rpx solid #f6f6f9;
    .title-one{
      margin-bottom: 10rpx;
      display: flex;
      flex-direction: row;
      align-items: center;
    }
    .title {
      font-size: 32rpx;
      color: #333;
      font-weight: bold;
      
      max-width: 80%;
    }
    .shuzi{
      color: red;
      font-size: 33rpx;
      font-weight: bold;
      margin-left: auto;
    }
    .lv{
      color: green;
    }
    .content {
      font-size: 26rpx;
      color: #666;
    }
  }
  .jione{
    width: 100%;
    height: 240rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: rgba(21,158,155,1);
    .fenname{
      color: #fff;
      font-size: 32rpx;
      font-weight: bold;

    }
    .fennum{
      font-size: 26rpx;
      color: #fff;
      font-weight: bold;
      display: block;
      margin-top: 15rpx;
      .nums{
        font-size: 40rpx;
        display: inline-block;
        margin-left: 10rpx;
      }
    }
  }
</style>
